ABC288 C - Don’t be cycle
提出
code: python
from collections import deque
n, m = list(map(int, input().split()))
g = [[] for _ in range(n+1)]
for a, b in ab:
# 1 <-> 2, 3 && 2<->3
# 4 <-> 5, 6 && 5<->6
# 閉路を持つ =>
# 消す =>
q = deque()
count = 0
while q:
next = q.popleft()
visit = 0
for i in next:
visit += 1
else:
if len(next) > 1 and visit == len(next):
count += 1
print(0) if count == 0 else print(count - 1)
解答
code: python
from collections import deque, defaultdict
n, m = map(int, input().split())
d = defaultdict(list)
for a, b in ab:
# グラフの連結成分(独立した部分)の個数
s = 0
# 最大で L 本の辺を残すことができるとすると、元の問題の答えは M−L
# L = N−S
for i in range(1, n+1):
s += 1
while que:
next = que.popleft()
que.append(j)
print(m - n + s)
テーマ
メモ
https://scrapbox.io/files/63ed8478f0e9d5001bcf45e3.png
提出
code: python
from collections import defaultdict
from collections import deque
n, m = map(int, input().split())
d = defaultdict(list)
for a, b in ab:
# print(d)
# {1: 2, 3, 2: 1, 3, 4, 3: 1, 2, 4: 2, 6, 5, 6: 5, 4, 5: 6, 4} que = deque()
que.append(1)
while que:
next = que.popleft()
break
else:
que.append(j)
print(sum(close))